package org.hawk.gwtppc.webtest.tests.classsuite;

import java.lang.reflect.ParameterizedType;
import java.lang.reflect.WildcardType;
import java.util.ArrayList;
import java.util.Map;

import org.hawk.gwtppc.webtest.common.Asserts;
import org.hawk.gwtppc.webtest.common.Test;
import org.hawk.gwtppc.webtest.tests.mock.ClassMock;
import org.hawk.gwtppc.webtest.tests.mock.GenericClassMock;
import org.hawk.gwtppc.webtest.tests.mock.SubClassMock1;

public class GetGenericSuperclassTest implements Test {

	public void run() throws Throwable {
		Asserts.assertEquals(SubClassMock1.class.getGenericSuperclass(), ClassMock.class);
		ParameterizedType type = (ParameterizedType)GenericClassMock.class.getGenericSuperclass();
		Asserts.assertFalse(type == null);
		Asserts.assertEquals(type.toString(), "java.util.ArrayList<java.util.Map<java.lang.String, ? extends java.lang.Number>>");
		Asserts.assertEquals(type.getActualTypeArguments().length, 1);
		Asserts.assertTrue(type.getOwnerType() == null);
		Asserts.assertEquals(type.getRawType(), ArrayList.class);
		
		ParameterizedType param = (ParameterizedType) type.getActualTypeArguments()[0];
		Asserts.assertFalse(param == null);
		Asserts.assertEquals(param.toString(), "java.util.Map<java.lang.String, ? extends java.lang.Number>");
		Asserts.assertEquals(param.getActualTypeArguments().length, 2);
		Asserts.assertTrue(param.getOwnerType() == null);
		Asserts.assertEquals(param.getRawType(), Map.class);
		
		Asserts.assertEquals(param.getActualTypeArguments()[0], String.class);
		
		WildcardType wild = (WildcardType) param.getActualTypeArguments()[1];
		Asserts.assertFalse(wild == null);
		Asserts.assertEquals(wild.getLowerBounds().length, 0);
		Asserts.assertEquals(wild.getUpperBounds().length, 1);
		Asserts.assertEquals(wild.getUpperBounds()[0], Number.class);
	}

	public String getName() {
		return "getGenericSuperclass()";
	}

}
